package com.zzyl.nursing.controller.member;

import java.util.List;
import java.util.Map;
import javax.servlet.http.HttpServletResponse;

import com.zzyl.common.core.domain.R;
import com.zzyl.nursing.domain.Elder;
import com.zzyl.nursing.dto.ElderDto;
import com.zzyl.nursing.domain.DeviceData;
import com.zzyl.nursing.dto.DeviceDataPointDto;
import com.zzyl.nursing.dto.FamilyMemberDto;
import com.zzyl.nursing.service.IDeviceService;
import com.zzyl.nursing.vo.FamilyMemberElderVo;
import com.zzyl.nursing.vo.DeviceFunctionHistoryQueryVo;
import com.zzyl.nursing.vo.LoginVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.zzyl.common.core.controller.BaseController;
import com.zzyl.common.core.domain.AjaxResult;
import com.zzyl.common.enums.BusinessType;
import com.zzyl.nursing.domain.FamilyMember;
import com.zzyl.nursing.service.IFamilyMemberService;
import com.zzyl.common.utils.poi.ExcelUtil;
import com.zzyl.common.core.page.TableDataInfo;

/**
 * 老人家属Controller
 *
 * @author ruoyi
 * @date 2025-06-05
 */
@RestController
@RequestMapping("/member/user")
@Api(tags = "老人家属相关接口")
public class FamilyMemberController extends BaseController {
    @Autowired
    private IFamilyMemberService familyMemberService;

    @Autowired
    private IDeviceService deviceService;


    /**
     * 查询老人家属列表
     */
    @PostMapping("/login")
    @ApiOperation(value = "小程序登录")
    public AjaxResult login(@RequestBody FamilyMemberDto familyMemberDto) {
        LoginVo loginVo = familyMemberService.login(familyMemberDto);
        return AjaxResult.success(loginVo);
    }

    /**
     * 绑定老人
     */
    @PostMapping("/add")
    @ApiOperation(value = "绑定老人")
    public R add(@RequestBody ElderDto elderDto) {
        familyMemberService.add(elderDto);
        return R.ok();
    }

    /**
     * 查询老人家属列表
     */
    @GetMapping("/my")
    @ApiOperation(value = "获取我的家人")
    public AjaxResult myFamily() {
        List<ElderDto> list = familyMemberService.getMyFamily();
        return AjaxResult.success(list);
    }

    /**
     * 查看已绑定家人列表（分页查询）
     */
    @GetMapping("/list-by-page")
    @ApiOperation(" 查看已绑定家人列表（分页查询）")
    public AjaxResult listByPage(@ApiParam("分页参数") Integer pageNum, Integer pageSize) {
        List<FamilyMemberElderVo> list = familyMemberService.listByPage(pageNum, pageSize);
        return AjaxResult.success(list);
    }
/**
 * 查询健康数据
 */
@GetMapping("/queryServiceProperties/{iotId}")
@ApiOperation(value = "查询设备服务属性")
public R<List<Map<String, Object>>> queryServiceProperties(@PathVariable String iotId){
    List<Map<String, Object>> list = deviceService.queryServiceProperties(iotId);
    return R.ok(list);
    }

    /**
     * WX小程序端 按天统计查询指标数据
     * @return
     */
    @ApiOperation(value = "WX小程序端 按天统计查询指标数据")
    @GetMapping("/queryDeviceDataListByDay")
    public AjaxResult queryDeviceDataListByDay(DeviceFunctionHistoryQueryVo deviceFunctionHistoryQueryVo){
       List<DeviceDataPointDto> list = familyMemberService.queryDeviceDataListByDay(deviceFunctionHistoryQueryVo);
       return AjaxResult.success(list);
    }


    /**
     * WX小程序端 按周统计查询指标数据
     * @return
     */
    @ApiOperation(value = "WX小程序端 按天统计查询指标数据")
    @GetMapping("/queryDeviceDataListByWeek")
    public AjaxResult queryDeviceDataListByWeek(DeviceFunctionHistoryQueryVo deviceFunctionHistoryQueryVo){
        List<DeviceDataPointDto> list = familyMemberService.queryDeviceDataListByWeek(deviceFunctionHistoryQueryVo);
        return AjaxResult.success(list);
    }


}
